<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<script type="text/javascript" charset="utf-8" src="${ctx}/editor/kindeditor-min.js"></script>

<div>
	<form id="f_article" action="<c:url value='/admin/klg/saveArticle.do'/>" method="post" enctype="multipart/form-data">
		<input type="hidden" name="article.articleid" value="${article.articleid}">
		<table id="t_sight_detail">
			<tr>
			<th width="75px">文章标题</th>
				<td>
					<input type="text" name="article.title" value="${article.title}"/>
				</td>
			</tr>
			<tr>
			<th width="75px">是否可用</th>
				<td>
					<input type="checkbox" id="f_article_enabled" name="article.enabled" value="1"/>
					<script type="text/javascript">
						var articleEnabled = "<c:out value='${article.enabled}' />";
						var articleEnabledValue = parseInt(articleEnabled);
						if(articleEnabledValue == 1){
							$("#f_article_enabled").attr("checked",true);
					  	}
					</script>
				</td>
			</tr>
			<tr>
			<th width="75px">是否可以回复</th>
				<td>
					<input type="checkbox" id="f_article_reply" name="article.reply" value="1"/>
					<script type="text/javascript">
						var articlereply = "<c:out value='${article.reply}' />";
						var articlereplyValue = parseInt(articlereply);
						if(articleEnabledValue == 1){
							$("#f_article_reply").attr("checked",true);
					  	}
					</script>
				</td>
			</tr>
			<tr>
			<th width="75px">分类</th>
				<td>
					<select id="parentType" name="parentType"></select>
					<select id="valueType" name="valueType"></select>
				</td>
			</tr>
			<tr>
				<th width="75px">内容</th>
				<td>
					<textarea id="article_content" name="article.content" rows="150" cols="80" style="width:600px;height:300px"><c:out value='${article.content}'/></textarea>
				</td>
			</tr>
			<tr>
				<td><input type="submit" name="保存" value="保存"/></td>
			</tr>
		</table>
	</form>
</div>
<script type="text/javascript">
KE.show({
	id : 'article_content',
	imageUploadJson : ctx+'/h/keditor.do',
	fileManagerJson : ctx + '/editor/jsp/file_manager_json.jsp',
	allowFileManager : true,
	afterCreate : function(id) {
		KE.event.ctrl(document, 13, function() {
			KE.util.setData(id);
			document.forms['article_content'].submit();
		});
		KE.event.ctrl(KE.g[id].iframeDoc, 13, function() {
			KE.util.setData(id);
			document.forms['article_content'].submit();
		});
	}
});

$(document).ready(function(){
	var url = ctx + '/json/segment/get.do?module=klg&level=1';
	$.getJSON(url, function(data){
		for(var i=0; i<data.segments.length;i++){
			$('#parentType').append('<option value='+data.segments[i].value+'>'+data.segments[i].text+'</option>');
		}
	});
	$('#parentType').change(function(){
		var id=$("#parentType").val();
		var url = ctx + '/json/segment/get.do?module=klg&level=2&id='+id;
		$('#valueType').html('');
		$.getJSON(url, function(data){
			for(var i=0; i<data.segments.length;i++){
				$('#valueType').append('<option value='+data.segments[i].value+'>'+data.segments[i].text+'</option>');
			}
		});
	});
	setTimeout(function(){
       $("#parentType").trigger('change');
    }, 1000);
});
</script>